//
//  OrderCarPayTypeCell.m
//  BaseProject
//
//  Created by 王洋 on 2021/5/17.
//  Copyright © 2021 王洋. All rights reserved.
//

#import "OrderCarPayTypeCell.h"

@implementation OrderCarPayTypeCell

- (void)awakeFromNib {
    [super awakeFromNib];

    [self.allPayControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.OrderCarPayTypeCellBlock) {
            self.OrderCarPayTypeCellBlock(YES);
        }
    }];
    
    [self.dingjinControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        
        if (self.model.deposit > 0) {
            if (self.OrderCarPayTypeCellBlock) {
                self.OrderCarPayTypeCellBlock(NO);
            }
        } else {
            
        }
    }];

}

- (void)fillCellWithModel:(SubmitInfoModel *)model {

    self.model = model;
    
    if (model.deposit > 0) {
        self.dingjinMoneyLab.text =[NSString stringWithFormat:@"需先付%@",[Utilities changeDoubleToString:model.deposit]];
    } else {
        self.dingjinMoneyLab.text =@"不支持意向金支付";

    }
    [self refreshWith:model.isAllPay];
}


- (void)refreshWith:(BOOL)isAllPay {
    
    if (isAllPay) {
        
        self.allPayControl.backgroundColor = UIColorHex(0xfff0f8);
        self.allPayLab.textColor = UIColorHex(0xff4242);
        self.dingjinControl.backgroundColor = UIColorHex(0xffffff);
        self.dingjinLab.textColor = UIColorHex(0x333333);
        self.dingjinMoneyLab.textColor = UIColorHex(0x666666);
        self.allPayTagImg.hidden = NO;
        self.dingjinTagImg.hidden = YES;
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.allPayControl pp_clipCorners:UIRectCornerAllCorners radius:8 border:1 color:UIColorHex(0xff4242)];
            [self.dingjinControl pp_clipCorners:UIRectCornerAllCorners radius:8 border:1 color:UIColorHex(0x999999)];
        });

    } else {
        
        self.allPayControl.backgroundColor = UIColorHex(0xffffff);
        self.allPayLab.textColor = UIColorHex(0x333333);
        self.dingjinControl.backgroundColor = UIColorHex(0xfff0f8);
        self.dingjinLab.textColor = UIColorHex(0xff4242);
        self.dingjinMoneyLab.textColor = UIColorHex(0xff4242);
        self.allPayTagImg.hidden = YES;
        self.dingjinTagImg.hidden = NO;
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.allPayControl pp_clipCorners:UIRectCornerAllCorners radius:8 border:1 color:UIColorHex(0x999999)];
            [self.dingjinControl pp_clipCorners:UIRectCornerAllCorners radius:8 border:1 color:UIColorHex(0xff4242)];
        });
    }
    
    if (self.model.deposit == 0) {

        self.dingjinControl.backgroundColor = UIColorHex(0xffffff);
        self.dingjinLab.textColor = UIColorHex(0x999999);
        self.dingjinMoneyLab.textColor = UIColorHex(0x999999);
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.dingjinControl pp_clipCorners:UIRectCornerAllCorners radius:8 border:1 color:UIColorHex(0xcccccc)];
        });
    }
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.allPayControl.layer.cornerRadius = 8;
    self.dingjinControl.layer.cornerRadius = 8;
    self.payTypeBGView.layer.cornerRadius = 8;

}

@end
